﻿#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace PdfCreative.Pdf.Writer.Utilities
{
    /// <summary>
    /// The ConversionUtilities class is a static library class that provides convenience methods for conversion between various data types.
    /// </summary>
    internal static class ConversionUtilities
    {
        // Public methods
        // ==============
        #region Public methods
        /// <summary>
        /// Reads a integer value out of a string.
        /// </summary>
        /// <param name="value">The string value</param>
        /// <returns>The integer value, or 0 of the string didn't contain a integer value.</returns>
        public static int ReadInt32(string value)
        {
            int result = 0;
            if (false == String.IsNullOrEmpty(value))
                Int32.TryParse(value, out result);

            return result;
        } // ReadInt32

        /// <summary>
        /// Reads a long value out of a string.
        /// </summary>
        /// <param name="value">The string value</param>
        /// <returns>The long value, or 0 of the string didn't contain a long value.</returns>
        public static long ReadLong(string value)
        {
            long result = 0L;
            if (false == String.IsNullOrEmpty(value))
                try { result = long.Parse(value); }
                catch (OverflowException) { }
                catch (FormatException) { }

            return result;
        } // ReadLong
        #endregion

    } // ConversionUtilities
}
